const app = getApp()
import {
  axios
} from "../../api/http.js";
import {
  GetCommodity,getComment
} from "../../api/Url"
Page({
  gotoHotSales() {
    wx.navigateTo({
      url: '../HotSales/HotSales'
    })
  },
  gotomy() {
    wx.switchTab({
      url: '../My/My',
    })
  },
  scroll(e) {
    console.log(e)
  },
  hideInput: function () {
    wx.navigateTo({
      url: '../all/all'
    })
  },
  handleChange({
    detail
  }) {
    this.setData({
      current: detail.key

    });
  },
  gotoshoopcar() {
    wx.switchTab({
      url: '../shoopcar/shoopcar',
    })
  },
  gotohome() {
    wx.switchTab({
      url: '../home/home',
    })
  },
  xs() {
    this.setData({
      visible1: false
    })
  },
  xss() {
    this.setData({
      visible2: false
    })
  },
  handleChangeScroll({
    detail
  }) {
    this.setData({
      current_scroll: detail.key
    });
  },
  tap: function (e) {
    this.setData({
      x: 30,
      y: 30
    });
  },
  onChange: function (e) {
    console.log(e.detail)
  },
  onScale: function (e) {
    console.log(e.detail)
  },
  data: {
    nbTitle: '商品详情',

    minusStatus: 'disable',
    x: 0,
    y: 0,

    kucun: 99,
    current: 'tab1',
    current_scroll: 'tab1',

    iconSize: 20,
    iconColor: 'green',
    iconType: 'success',

    swiperCurrent: 0,
    indicatorDots: true,
    autoplay: true,
    interval: 3000,
    duration: 800,
    circular: true,
    indicatorCo: "#ffdfdc",
    indicatoraAC: "#ff948a",
    list: {},
    links: [
      '../user/user',
      '../user/user',
      '../user/user'
    ],
    visible: false,
    visible1: false,
    visible2: false,
    iconone: false,
    icontow: false,
    iconsui: false,

    color1: "颜色分类",
    size1: "尺寸",
    num1: 1,
    sizeImg1: "",
    color2: "颜色分类",
    size2: "尺寸",
    num2: 1,
    sizeImg2: "",

    comment:[]
  },
  bindColor1(e) {
    this.setData({
      sizeImg1: e.currentTarget.dataset.src,
      color1: e.currentTarget.dataset.color
    })
  },
  bindSize1(e) {
    this.setData({
      size1: e.currentTarget.dataset.size
    })
  },
  bindManual1: function (e) {
    var num = e.detail.value;
    var minusStatus = num > 1 ? 'normal' : 'disable';
    this.setData({
      num1: num,
      minusStatus: minusStatus
    })
  },
  bindPlus1: function () {
    var num = this.data.num1;
    num++;
    var minusStatus = num > 1 ? 'normal' : 'disable';
    this.setData({
      num1: num,
      minusStatus: minusStatus
    })
  },
  bindMinus1: function () {
    var num = this.data.num1;
    if (num > 1) {
      num--;
    }
    var minusStatus = num > 1 ? 'normal' : 'disable';
    this.setData({
      num1: num,
      minusStatus: minusStatus
    })
  },
  bindColor2(e) {
    this.setData({
      sizeImg2: e.currentTarget.dataset.src,
      color2: e.currentTarget.dataset.color
    })
  },
  bindSize2(e) {
    this.setData({
      size2: e.currentTarget.dataset.size
    })
  },
  bindManual2: function (e) {
    var num = e.detail.value;
    var minusStatus = num > 1 ? 'normal' : 'disable';
    this.setData({
      num2: num,
      minusStatus: minusStatus
    })
  },
  bindPlus2: function () {
    var num = this.data.num2;
    num++;
    var minusStatus = num > 1 ? 'normal' : 'disable';
    this.setData({
      num2: num,
      minusStatus: minusStatus
    })
  },
  bindMinus2: function () {
    var num = this.data.num2;
    if (num > 1) {
      num--;
    }
    var minusStatus = num > 1 ? 'normal' : 'disable';
    this.setData({
      num2: num,
      minusStatus: minusStatus
    })
  },
  bindGotoshoopcar() {
    if (this.data.color1 == "颜色分类" || this.data.size1 == "尺寸") {
      wx.showModal({
        title: '提示',
        content: '请选择颜色和尺寸~',
        success(res) {
          if (res.confirm) {
            console.log('用户点击确定')
          } else if (res.cancel) {
            console.log('用户点击取消')
          }
        }
      })
      return
    }
    var params = {
      falg: false,
      orderFormDetails: {
        //商品图片
        commodityImg: this.data.list.commodityImgBig,
        //商品名称
        commodityTitle: this.data.list.commodityTitle,
        // 商品价格
        commodityPrice: parseFloat(this.data.list.maxPrice),
        //商品数量
        commodityNum: parseFloat(this.data.num1),
        //商品尺寸
        commoditySize: this.data.size1,
        //商品颜色
        commodityColor: this.data.color1
      },
      //订单号
      orderNumber: parseFloat(new Date().getTime()),
      //订单状态   0 代付款   1 待发货   2 待收货   3 待评价  5 退款
      orderStatus: parseFloat(0),
      //下单时间
      orderTime: parseFloat(new Date().getTime()),
      //购物用户
      orderUser: app.globalData.openId
    }
    app.globalData.shopCar = [...app.globalData.shopCar, params]
    console.log(params)
    wx.switchTab({
      url: '../shoopcar/shoopcar?parmas=' + params,
    })
  },
  
  bindGotoPlaceOrder() {
    if (this.data.color2 == "颜色分类" || this.data.size2 == "尺寸") {
      wx.showModal({
        title: '提示',
        content: '请选择颜色和尺寸~',
        success(res) {
          if (res.confirm) {
            console.log('用户点击确定')
          } else if (res.cancel) {
            console.log('用户点击取消')
          }
        }
      })
      return
    }
    var params = {
      falg: false,
      orderFormDetails: {
        //商品图片
        commodityImg: this.data.list.commodityImgBig,
        //商品名称
        commodityTitle: this.data.list.commodityTitle,
        // 商品价格
        commodityPrice: parseFloat(this.data.list.maxPrice),
        //商品数量
        commodityNum: parseFloat(this.data.num1),
        //商品尺寸
        commoditySize: this.data.size1,
        //商品颜色
        commodityColor: this.data.color1
      },
      //订单号
      orderNumber: parseFloat(new Date().getTime()),
      //订单状态   0 代付款   1 待发货   2 待收货   3 待评价  5 退款
      orderStatus: parseFloat(0),
      //下单时间
      orderTime: parseFloat(new Date().getTime()),
      //购物用户
      orderUser: app.globalData.openId
    }
    app.globalData.zhl = [...app.globalData.orderList, params]
    wx.navigateTo({
      url: '../placeorders/placeorders',
    })
  },
  iconone() {
    this.setData({
      iconone: true
    })
  },
  icontow() {
    this.setData({
      icontow: true
    })
  },
  iconones() {
    this.setData({
      iconone: false
    })
  },
  icontows() {
    this.setData({
      icontow: false
    })
  },
  iconsuis() {
    this.setData({
      iconsui: false
    })
  },
  fenxiang: function () {
    this.setData({
      visible: true
    })
  },
  handleCancel() {
    this.setData({
      visible: false
    });
  },
  handleOpen1() {
    this.setData({
      visible1: true
    });
  },

  handleCancel1() {
    this.setData({
      visible1: false,
      color1: "颜色分类",
      size1: "尺寸",
      sizeImg1: "",
    });
  },

  handleOpen2() {
    this.setData({
      visible2: true
    });
  },

  handleCancel2() {
    this.setData({
      visible2: false,
      color2: "颜色分类",
      size2: "尺寸",
      sizeImg2: "",
    });
  },


  /**
   * 生命周期函数--监听页面加载
   */
  goToMake(){
    console.log(123)
    wx.navigateTo({
      url: '../comment/comment',
    })
  },
  onLoad: function (options) {
    console.log(options.Id)
    axios(GetCommodity, {
      id: options.Id
    }, "post", (res) => {
      console.log(res)
      this.setData({
        list: res
      })
    })
    axios(getComment,{},"get",(res)=>{
      console.log(res)
      this.setData({
        comment:res
      })
    })
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
})